package com.codemonkey.lq.extend.excelverification.impl;

import com.codemonkey.lq.extend.excelverification.AbstractVerifier;
import com.codemonkey.lq.extend.excelverification.CellContext;
import com.codemonkey.lq.extend.excelverification.spi.Continuable;

/**
 * 不允许为null或""
 * @author LQ
 *
 */
public final class NotNullableVerifier extends AbstractVerifier implements Continuable {

	private boolean isNotEmpty = false;

	@Override
	protected boolean doVerify(CellContext cellContext) {
		final Object cellVal = cellContext.getCellVal();

		isNotEmpty = (null != cellVal && "" != cellVal.toString());

		return isNotEmpty;
	}

	@Override
	public String getReadableFailMsg(CellContext cellContext) {
		if (isNotEmpty) {
			return "";
		} else {
			return String.format("[ %s ] can not be null or empty", cellContext.getCellName());
		}

	}

	@Override
	public boolean isContinue(CellContext cellContext) {
		return isNotEmpty;
	}

}
